﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using Aribaccio;

namespace BDPAutodetect.Models
{
    public partial class MUserDto : ObservableModel
    {
        /// <summary>
        /// ID编号
        /// </summary>
        public int ID { get; set; }

        /// <summary>
        /// 角色实例
        /// </summary>
        [ObservableProperty]
        [NotifyPropertyChangedFor(nameof(Supered))]
        protected MRoleDto? role;

        /// <summary>
        /// 名称
        /// </summary>
        [ObservableProperty]
        protected string name;

        /// <summary>
        /// 别称
        /// </summary>
        [ObservableProperty]
        protected string nameNick;

        /// <summary>
        /// 密码
        /// </summary>
        [ObservableProperty]
        protected string password;

        /// <summary>
        /// 显示密码（明文密码）
        /// </summary>
        [ObservableProperty]
        protected string passwordDisplay;

        /// <summary>
        /// 冻结状态(默认0非冻结状态，1冻结状态)
        /// </summary>
        [ObservableProperty]
        protected int freezed;

        /// <summary>
        /// 登录状态(默认0非登录状态，1登录状态)
        /// </summary>
        [ObservableProperty]
        protected int logined;

        /// <summary>
        /// 超级状态(默认0非超级状态，1超级状态) 
        /// </summary>
        public int Supered => this.Role?.Supered ?? 0;

        public MUserDto()
        {
            this.Name = string.Empty;
            this.NameNick = string.Empty;
            this.Password = string.Empty;
            this.PasswordDisplay = string.Empty;
        }

        public MUserDto(int argID, string argName)
        {
            this.ID = argID;
            this.Name = argName;
            this.NameNick = string.Empty;
            this.Password = string.Empty;
            this.PasswordDisplay = string.Empty;
        }

        public MUserDto CloneDeep()
        {
            return new MUserDto(this.ID, this.Name)
            {
                Role = this.Role,
                NameNick = this.NameNick,
                Password = this.Password,
                PasswordDisplay = this.PasswordDisplay,
                Freezed = this.Freezed,
                Logined = this.Logined
            };
        }

        public TBasicUser CloneTData()
        {
            return new TBasicUser()
            {
                ID = this.ID,
                RoleID = this.Role?.ID ?? 0,
                Name = this.Name,
                NameNick = this.NameNick,
                Password = this.Password,
                Freezed = this.Freezed,
                Logined = this.Logined
            };
        }

    }
}
